import echarts from 'echarts'
import wordCloud   from 'echarts-wordcloud'
import 'echarts-liquidfill'
import '../../../node_modules/echarts/map/js/china.js' // 引入中国地图数据

export default {
  chinaConfigure(myEchart, data) {
    const myChart = echarts.init(myEchart) //这里是为了获得容器所在位置 
    myChart.setOption({ // 进行相关配置
      title: {
        text: '中国高校分布',
        subtext: 'China',
        x: 'center'
      },
      tooltip: {
        trigger: 'item',
        position: 'bottom',
        formatter: function(params) {
          var res = params.name + ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
          var count = params.data == undefined ? '0' : params.data.count
          res += '高校数量 : ' + count + '</br>----------------------------</br>'

          if (params.data != undefined && params.data.count > 0) {
            for (var i = 0; i < params.data.cus.length; i++) {
              res += params.data.cus[i] + '</br>'
            }
          }
          return res
        },
      }, // 鼠标移到图里面的浮动提示框
      geo: {
        map: 'china',
        roam: false,
        zoom: 1.2,
        label: {
          show: true,
          emphasis: {
            show: true
          }
        },
        itemStyle: {
          normal: {
            borderWidth: .5, //区域边框宽度
            borderColor: '#009fe8', //区域边框颜色
            areaColor: '#ffefd5', //区域颜色
          },
          emphasis: {
            label: {
              show: true
            }, //鼠标移入城市名称是否展示
            borderWidth: .51,
            borderColor: '#4b0082',
            areaColor: '#ffdead',
          }
        },
        regions: [ //对不同的区块进行着色
          {
            name: '新疆',
            itemStyle: {
              normal: {
                areaColor: '#fbd8f3'
              }
            }
          },
          {
            name: '青海',
            itemStyle: {
              normal: {
                areaColor: '#fbd8f2'
              }
            }
          },
          {
            name: '北京',
            itemStyle: {
              normal: {
                areaColor: '#f1ebd0'
              }
            }
          },
          {
            name: '天津',
            itemStyle: {
              normal: {
                areaColor: '#f1ebd1'
              }
            }
          },
          {
            name: '上海',
            itemStyle: {
              normal: {
                areaColor: '#feffdb'
              }
            }
          },
          {
            name: '重庆',
            itemStyle: {
              normal: {
                areaColor: '#8ba1de'
              }
            }
          },
          {
            name: '河北',
            itemStyle: {
              normal: {
                areaColor: '#fde8cd'
              }
            }
          },
          {
            name: '河南',
            itemStyle: {
              normal: {
                areaColor: '#e4f1d7'
              }
            }
          },
          {
            name: '云南',
            itemStyle: {
              normal: {
                areaColor: '#fffed7'
              }
            }
          },
          {
            name: '辽宁',
            itemStyle: {
              normal: {
                areaColor: '#e4f1d7'
              }
            }
          },
          {
            name: '黑龙江',
            itemStyle: {
              normal: {
                areaColor: '#e4f1d7'
              }
            }
          },
          {
            name: '湖南',
            itemStyle: {
              normal: {
                areaColor: '#fffed7'
              }
            }
          },
          {
            name: '安徽',
            itemStyle: {
              normal: {
                areaColor: '#fffed8'
              }
            }
          },
          {
            name: '山东',
            itemStyle: {
              normal: {
                areaColor: '#dccee7'
              }
            }
          },
          {
            name: '新疆',
            itemStyle: {
              normal: {
                areaColor: '#fffed7'
              }
            }
          },
          {
            name: '江苏',
            itemStyle: {
              normal: {
                areaColor: '#d2eafc'
              }
            }
          },
          {
            name: '浙江',
            itemStyle: {
              normal: {
                areaColor: '#ddceeb'
              }
            }
          },
          {
            name: '江西',
            itemStyle: {
              normal: {
                areaColor: '#e4f1d3'
              }
            }
          },
          {
            name: '湖北',
            itemStyle: {
              normal: {
                areaColor: '#fde8cd'
              }
            }
          },
          {
            name: '广西',
            itemStyle: {
              normal: {
                areaColor: '#fde8cd'
              }
            }
          },
          {
            name: '甘肃',
            itemStyle: {
              normal: {
                areaColor: '#f6fdc9'
              }
            }
          },
          {
            name: '山西',
            itemStyle: {
              normal: {
                areaColor: '#fffdd6'
              }
            }
          },
          {
            name: '内蒙古',
            itemStyle: {
              normal: {
                areaColor: '#ddcfe6'
              }
            }
          },
          {
            name: '陕西',
            itemStyle: {
              normal: {
                areaColor: '#fae2f0'
              }
            }
          },
          {
            name: '吉林',
            itemStyle: {
              normal: {
                areaColor: '#fce8cd'
              }
            }
          },
          {
            name: '福建',
            itemStyle: {
              normal: {
                areaColor: '#efdefa'
              }
            }
          },
          {
            name: '贵州',
            itemStyle: {
              normal: {
                areaColor: '#fad8e8'
              }
            }
          },
          {
            name: '广东',
            itemStyle: {
              normal: {
                areaColor: '#ddcfe8'
              }
            }
          },
          {
            name: '青海',
            itemStyle: {
              normal: {
                areaColor: '#fad8e9'
              }
            }
          },
          {
            name: '西藏',
            itemStyle: {
              normal: {
                areaColor: '#ddcfe6'
              }
            }
          },
          {
            name: '四川',
            itemStyle: {
              normal: {
                areaColor: '#e4f1d5'
              }
            }
          },
          {
            name: '宁夏',
            itemStyle: {
              normal: {
                areaColor: '#fefcd5'
              }
            }
          },
          {
            name: '海南',
            itemStyle: {
              normal: {
                areaColor: '#fad8e9'
              }
            }
          },
          {
            name: '台湾',
            itemStyle: {
              normal: {
                areaColor: '#fce8cd'
              }
            }
          },
          {
            name: '香港',
            itemStyle: {
              normal: {
                areaColor: '#dc9bbb'
              }
            }
          },
          {
            name: '澳门',
            itemStyle: {
              normal: {
                areaColor: '#e0f7cc'
              }
            }
          },
        ]
      },
      series: [{
        type: 'scatter',
        name: '高校数量',
        coordinateSystem: 'geo', // series坐标系类型
        symbolSize: 10,
        markPoint: {
          data: data

        },
      }],

    })
    return myChart
  },
  pieConfigure(myEchart, name, data) {
    const myPie = echarts.init(myEchart) //这里是为了获得容器所在位置    
    myPie.setOption({
      title: {
        text: name,
        left: 'left',
        y: '20'
      },
      tooltip: {
        trigger: 'item',
        position: 'bottom',
        formatter: '{a} <br/>{b} : {c} ({d}%)'
      },
      series: [{
        name: name,
        type: 'pie',
        radius: '40%',
        roseType: 'radius',
        itemStyle: {
          normal: {
            labelLine: {
              length: 15,
              length2: 1,
              length3: 1
            }
          }
        },
        data: data
      }]
    })
    return myPie
  },
  pie2Configure(myEchart, name, data) {
    const myPie = echarts.init(myEchart) //这里是为了获得容器所在位置    
    myPie.setOption({
      title: {
        text: name,
        left: 'left',
        y: '20'
      },
      tooltip: {
        trigger: 'item',
        position: 'bottom',
        formatter: '{a} <br/>{b} : {c} ({d}%)'
      },
      series: [{
        name: name,
        type: 'pie',
        radius:  ['20%', '50%'],
        itemStyle: {
          normal: {
            labelLine: {
              length: 15,
              length2: 1,
              length3: 1
            }
          }
        },
        data: data
      }]
    })
    return myPie
  },
  mapTreeConfigure(myEchart, name, data) {
    const mapTree = echarts.init(myEchart) //这里是为了获得容器所在位置    
    window.onresize = mapTree.resize
    var me= this
     // 随机颜色
    var randcolor = () => {
        var r = 100 + ~~(Math.random() * 100)
        var g = 135 + ~~(Math.random() * 100)
        var b = 100 + ~~(Math.random() * 100)
        return `rgb(${r}, ${g}, ${b})`
    }
    mapTree.setOption({

      title: {
        text: name
         
      },
        tooltip: {
          trigger: 'item',
          position: 'bottom',
          formatter:  function(params) {
                        
                          return  me.getContent(params)
                      }
        },
      'series': [{
          'name': '',
          'type': 'wordCloud',
          gridSize: 20,
          'sizeRange': [12, 30],
          'rotationRange': [0, 0],
          'shape': 'circle',
          height:'100%',
          width : '100%',
          drawOutOfBound:true,
            textStyle: {
                       normal: {
                         color: params => {
                                             return randcolor()
                                         }
                       },
                  },
          'data': data
      }]

    })
    return mapTree
  },
  mapTreeReserchConfigure(myEchart, name, data) {
    const mapTree = echarts.init(myEchart) //这里是为了获得容器所在位置    
    window.onresize = mapTree.resize
    var me= this
     // 随机颜色
    var randcolor = () => {
        var r = 100 + ~~(Math.random() * 100)
        var g = 135 + ~~(Math.random() * 100)
        var b = 100 + ~~(Math.random() * 100)
        return `rgb(${r}, ${g}, ${b})`
    }
    mapTree.setOption({
  
      title: {
        text: name
         
      },
        tooltip: {
          trigger: 'item',
          position: 'bottom',
        },
      'series': [{
          'name': '',
          'type': 'wordCloud',
          'sizeRange': [12, 30],
          'rotationRange': [0, 0],
          'shape': 'circle',
          height:'100%',
          width : '100%',
          drawOutOfBound:true,
            textStyle: {
                       normal: {
                         color: params => {
                                             return randcolor()
                                         }
                       },
                  },
          'data': data
      }]
  
    })
    return mapTree
  },
  getContent(params){
    var res = ''
    res += params.name + '</br>'
    res += '排名:' + params.data.rownum+ '</br>'
    
    var leaveType = params.data.leave_type 
    leaveType = leaveType== null? '' : leaveType.indexOf('A')>= 0? '优势学科' : ''
    if(leaveType != '')
      res += leaveType + '</br>'
    
    var leaveType = params.data.leave_type
    leaveType = leaveType== null? '' : leaveType.indexOf('A')>= 0? '优势学科' : ''
    res += params.data.leave_type== null? '': '学位中心评估:'+params.data.leave_type + '</br>'
    
    var name = params.name
    var value = params.subject2_id
    return res
  },
  mapLineConfigure(myEchart, name, data) {
    const mapLine = echarts.init(myEchart) //这里是为了获得容器所在位置    
    window.onresize = mapLine.resize
    var me= this
    mapLine.setOption({
      
          tooltip: {
              trigger: 'axis'
          },
          legend: {
              color: ['#F58080', '#47D8BE', '#F9A589'],
              data: data.legendData,
              left: 'center',
              bottom: 'bottom'
          },
          grid: {
              top: 'middle',
              left: '3%',
              right: '4%',
              bottom: '3%',
              height: '80%',
              containLabel: true
          },
          xAxis: {
              type: 'category',
              data: data.xAxisList,
              axisLine: {
                  lineStyle: {
                      color: '#999'
                  }
              }
          },
          yAxis: {
              type: 'value',
              minInterval: 1, 
              splitLine: {
                  lineStyle: {
                      type: 'dashed',
                      color: '#DDD'
                  }
              },
              axisLine: {
                  show: false,
                  lineStyle: {
                      color: '#333'
                  },
              },
              nameTextStyle: {
                  color: '#999'
              },
              splitArea: {
                  show: false
              }
          },
          series: [{
                  name: data.legendData[0],
                  type: 'line',
                  data: data.cuDataList,
                  color: '#F58080',
                  lineStyle: {
                      normal: {
                          width: 5,
                          color: {
                              type: 'linear',
      
                              colorStops: [{
                                  offset: 0,
                                  color: '#FFCAD4' // 0% 处的颜色
                              }, {
                                  offset: 0.4,
                                  color: '#F58080' // 100% 处的颜色
                              }, {
                                  offset: 1,
                                  color: '#F58080' // 100% 处的颜色
                              }],
                              globalCoord: false // 缺省为 false
                          },
                          shadowColor: 'rgba(245,128,128, 0.5)',
                          shadowBlur: 10,
                          shadowOffsetY: 7
                      }
                  },
                  itemStyle: {
                      normal: {
                          color: '#F58080',
                          borderWidth: 10,
                          /*shadowColor: 'rgba(72,216,191, 0.3)',
                           shadowBlur: 100,*/
                          borderColor: '#F58080'
                      }
                  },
                  smooth: true
              },
              {
                  name:  data.legendData[1],
                  type: 'line',
                  data: data.cu1DataList,
                  lineStyle: {
                      normal: {
                          width: 5,
                          color: {
                              type: 'linear',
      
                              colorStops: [{
                                      offset: 0,
                                      color: '#AAF487' // 0% 处的颜色
                                  },
                                  {
                                      offset: 0.4,
                                      color: '#47D8BE' // 100% 处的颜色
                                  }, {
                                      offset: 1,
                                      color: '#47D8BE' // 100% 处的颜色
                                  }
                              ],
                              globalCoord: false // 缺省为 false
                          },
                          shadowColor: 'rgba(71,216,190, 0.5)',
                          shadowBlur: 10,
                          shadowOffsetY: 7
                      }
                  },
                  itemStyle: {
                      normal: {
                          color: '#AAF487',
                          borderWidth: 10,
                          /*shadowColor: 'rgba(72,216,191, 0.3)',
                           shadowBlur: 100,*/
                          borderColor: '#AAF487'
                      }
                  },
                  smooth: true
              }
          ]

    })
    return mapLine
  },

  radialGradientConfigure(myEchart, plantCap, subject, legendData) {
        const map = echarts.init(myEchart) //这里是为了获得容器所在位置    
        var me= this
        var legendData = legendData
        var indicator = [{
                text: '专职教师',
                max: 30
            },
            {
                text: '专家',
                max: 30
            },
            {
                text: '团队',
                max: 30
            },
            {
                text: '重点学科',
                max: 30,
            },
            {
                text: '科学研究奖',
                max: 30
            },
            {
                text: '科研项目',
                max: 30
            },
            {
                text: '专利',
                max: 30
            },
            {
                text: '中文论文',
                max: 30
            },
            {
                text: '英文论文',
                max: 30
            },
            {
                text: '教学成果奖',
                max: 30
            },
            {
                text: '教材',
                max: 30
            },
            {
                text: '精品课程',
                max: 30
            },
            {
                text: '学位授予',
                max: 30
            }
            
        ]
        var dataArr = [
            {
                value: [17, 22, 10, 25, 15, 22,17, 22, 10, 25, 15, 22,30],
                name: legendData[0],
                itemStyle: {
                    normal: {
                        lineStyle: {
                            color: '#00D7FF',
                            // shadowColor: '#4BFFFC',
                            // shadowBlur: 10,
                        },
                        shadowColor: '#00D7FF',
                        shadowBlur: 10,
                    },
                },
                areaStyle: {
                    normal: { // 单项区域填充样式
                        color: {
                            type: 'linear',
                            x: 0, //右
                            y: 0, //下
                            x2: 1, //左
                            y2: 1, //上
                            colorStops: [{
                                offset: 0,
                                color: '#00D7FF'
                            }, {
                                offset: 0.5,
                                color: 'rgba(0,0,0,0)'
                            }, {
                                offset: 1,
                                color: '#00D7FF'
                            }],
                            globalCoord: false
                        },
                        opacity: 1 // 区域透明度
                    }
                }
            },
            {
                value: [15, 12, 17 ,29, 20, 18, 22, 10, 25, 15, 22,30,22],
                name: legendData[1],
                itemStyle: {
                    normal: {
                        lineStyle: {
                            color: '#C000FF',
                            // shadowColor: '#4A99FF',
                            // shadowBlur: 10,
                        },
                        shadowColor: '#C000FF',
                        shadowBlur: 10,
                    },
                },
                areaStyle: {
                        normal: { // 单项区域填充样式
                            color: {
                                type: 'linear',
                                x: 0, //右
                                y: 0, //下
                                x2: 1, //左
                                y2: 1, //上
                                colorStops: [{
                                    offset: 0,
                                    color: '#C000FF'
                                }, {
                                    offset: 0.5,
                                    color: 'rgba(0,0,0,0)'
                                }, {
                                    offset: 1,
                                    color: '#C000FF'
                                }],
                                globalCoord: false
                            },
                            opacity: 1 // 区域透明度
                        }
                    }
            },
            {
                value: [18, 19, 17 ,24, 22, 11, 21, 12, 22, 13, 21,24,22],
                name: legendData[2],
                itemStyle: {
                    normal: {
                        lineStyle: {
                            color: '#C000FF',
                            // shadowColor: '#4A99FF',
                            // shadowBlur: 10,
                        },
                        shadowColor: '#C000FF',
                        shadowBlur: 10,
                    },
                },
                areaStyle: {
                        normal: { // 单项区域填充样式
                            color: {
                                type: 'linear',
                                x: 0, //右
                                y: 0, //下
                                x2: 1, //左
                                y2: 1, //上
                                colorStops: [{
                                    offset: 0,
                                    color: '#C000FF'
                                }, {
                                    offset: 0.5,
                                    color: 'rgba(0,0,0,0)'
                                }, {
                                    offset: 1,
                                    color: '#C000FF'
                                }],
                                globalCoord: false
                            },
                            opacity: 1 // 区域透明度
                        }
                    }
            },
            {
                value: [12, 13, 17 ,21, 15, 21, 11, 22, 12, 23, 11,14,22],
                name: legendData[3],
                itemStyle: {
                    normal: {
                        lineStyle: {
                            color: '#C000FF',
                            // shadowColor: '#4A99FF',
                            // shadowBlur: 10,
                        },
                        shadowColor: '#C000FF',
                        shadowBlur: 10,
                    },
                },
                areaStyle: {
                        normal: { // 单项区域填充样式
                            color: {
                                type: 'linear',
                                x: 0, //右
                                y: 0, //下
                                x2: 1, //左
                                y2: 1, //上
                                colorStops: [{
                                    offset: 0,
                                    color: '#C000FF'
                                }, {
                                    offset: 0.5,
                                    color: 'rgba(0,0,0,0)'
                                }, {
                                    offset: 1,
                                    color: '#C000FF'
                                }],
                                globalCoord: false
                            },
                            opacity: 1 // 区域透明度
                        }
                    }
            }
            
        ]
        var colorArr = ['#00D7FF','#C000FF', '#2B30EB', '#eb587b']
        map.setOption({
    backgroundColor: '#101736',
    title: [{
        'text': subject,
        x: '45%',
        y: '1%',
        textStyle: {
            color: '#fff',
            fontSize: '25',
            fontWeight: 'lighter'
        },
        subtextStyle: {
            color: '#90979c',
            fontSize: '16',

        },
    }],
    color: colorArr,
    legend:{
        orient:'horizontal',
        icon: 'circle', //图例形状
        data: legendData,
        bottom:'90%',
         left:'10%',
        itemWidth: 14, // 图例标记的图形宽度。[ default: 25 ]
        itemHeight: 14, // 图例标记的图形高度。[ default: 14 ]
        itemGap: 21, // 图例每项之间的间隔。[ default: 10 ]横向布局时为水平间隔，纵向布局时为纵向间隔。
        textStyle: {
            fontSize: 18,
            color: '#fff',
        },
    },
    radar: {
        // shape: 'circle',
        name: {
            textStyle: {
                color: '#fff',
                fontSize: 18
            },
        },
        radius: ['0%', '60%'],
        center: ['50%', '50%'],
        indicator: indicator,
        splitArea: { // 坐标轴在 grid 区域中的分隔区域，默认不显示。
            show: true,
            areaStyle: { // 分隔区域的样式设置。
                color: ['rgba(255,255,255,0)', 'rgba(255,255,255,0)'], // 分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
            }
        },
        axisLine: { //指向外圈文本的分隔线样式
            lineStyle: {
                color: '#153269'
            }
        },
        splitLine: {
            lineStyle: {
                color: '#113865', // 分隔线颜色
                width: 1, // 分隔线线宽
            }
        },
    },
    tooltip: {
        show:true,
        trigger: 'item',
        
    },
    series: [{
        type: 'radar',
        symbolSize: 3,
        // symbol: 'angle',
        data: dataArr
    }]
})
        return map
      }
    
}